package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.api.platform.dto.user.UrlDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Url;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author xuchang
 */
public class UrlConverter {
    public static UrlDto do2Dto(Url domain){
        return Objects.isNull(domain) ? null: UrlDto.builder()
                .id(domain.getId())
                .component(domain.getComponent())
                .iconCls(domain.getIconCls())
                .requireAuth(domain.getRequireAuth())
                .name(domain.getName())
                .url(domain.getUrl())
                .path(domain.getPath())
                .deleted(domain.getDeleted())
                .build();
    }

    public static List<UrlDto> do2Dto(List<Url> domain){
        return CollectionUtils.isEmpty(domain) ? java.util.Collections.emptyList() : domain.stream().map(UrlConverter::do2Dto).collect(Collectors.toList());
    }

    public static Url dto2Do(UrlDto dto){
        return Objects.isNull(dto) ? null: Url.builder()
                .id(dto.getId())
                .component(dto.getComponent())
                .iconCls(dto.getIconCls())
                .requireAuth(dto.getRequireAuth())
                .name(dto.getName())
                .url(dto.getUrl())
                .path(dto.getPath())
                .deleted(dto.getDeleted())
                .build();
    }

    public static List<Url> dto2Do(List<UrlDto> dto){
        return CollectionUtils.isEmpty(dto) ? java.util.Collections.emptyList() : dto.stream().map(UrlConverter::dto2Do).collect(Collectors.toList());
    }
}
